﻿////////////////////////////////////////////////////////////////////
//
//	Map_FVG C# Class Library.
//
//	ElencoSentieri
//
//	autore: Gustavo Mainardi 
//	versione: 1.0
//	data: 01/12/2015
//
//
//	Cronologia delle versioni:
//
//	Versione 1.0 01/12/2015
//		versione originale
//
//////////////////////////////////////////////////////////////////////////
using System;
using System.Windows.Forms;


namespace Map_Fvg
{
    public partial class ElencoSentieri : Form
    {
        public static int option;

        static int maxNumSelez = 10;
        public static int inum;
        private static int number;
        public static int[] numSelez = new int[maxNumSelez];

        public ElencoSentieri()
        {
            InitializeComponent();
            textBox1.Text = "( seleziona )";
            textBox1.Visible = true;
            button2.Visible = false;
            button3.Visible = false;
            inum = 0;
        }

        private void infoDialog11_Load(object sender, EventArgs e)
        {
            if (ViewQ.nShapes == 0)
            {
                MessageBox.Show("elenco linee vuoto");
                return;
            }

            int isel;
            if (option == 0)
            {
                isel = -1;
            }
            else
            { 
                isel = ViewQ.selected_linea;
            }

            int noSent = 0;
            for (int i = 0; i < ViewQ.nShapes; ++i)
            {
                int pntSimb = ViewQ.vectShapes[i].pntSimb;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L000MU")) ++noSent;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L000SE")) ++noSent;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L000SI")) ++noSent;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L001SE")) ++noSent;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L002SE")) ++noSent;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L003SE")) ++noSent;
            }

            if (noSent == 0)
            {
                MessageBox.Show("non vi sono sentieri");
                return;
            }

            dataGridView1.ColumnCount = 5;
            this.dataGridView1.Columns[0].HeaderText = "numero";
            this.dataGridView1.Columns[1].HeaderText = "codice";
            this.dataGridView1.Columns[2].HeaderText = "denom. codice";
            this.dataGridView1.Columns[3].HeaderText = "lunghezza";
            this.dataGridView1.Columns[4].HeaderText = "quota media";

            this.dataGridView1.Columns[0].Width = 70;
            this.dataGridView1.Columns[1].Width = 80;
            this.dataGridView1.Columns[2].Width = 150;
            this.dataGridView1.Columns[3].Width = 80;
            this.dataGridView1.Columns[4].Width = 80;

            dataGridView1.AllowUserToAddRows = false;
            dataGridView1.AllowUserToDeleteRows = false;

            bool bSent;

            for (int i = 0; i < ViewQ.nShapes; ++i)
            {
                if (i == isel) continue;
                if(ViewQ.vectShapes[i].modifica == 2) continue;
                if (ViewQ.vectShapes[i].modifica == 5) continue;
                int pntSimb = ViewQ.vectShapes[i].pntSimb;
                bSent = false;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L000MU")) bSent = true;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L000SE")) bSent = true;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L000SI")) bSent = true;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L001SE")) bSent = true;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L002SE")) bSent = true;
                if (ViewQ.vectS[pntSimb].codice.Contains("5L003SE")) bSent = true;
                if (!bSent) continue;
                string[] row = new string[] {
                     i.ToString(),  //  ViewQ.vectShapes[i].numID.ToString(),    
                     ViewQ.vectS[pntSimb].codice.ToString(),
                     ViewQ.vectS[pntSimb].denom.ToString(),
                     ViewQ.vectShapes[i].lunghezza,
                    ViewQ.vectShapes[i].quota.ToString()
                };
                this.dataGridView1.Rows.Add(row);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            option = 0;
            inum = 0;
            this.Close();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            string ss = dataGridView1[0, e.RowIndex].Value.ToString();
            number = int.Parse(ss);
            if (option == 0)
            {
                button2.Visible = true;
                button3.Visible = true;
                textBox1.Visible = false;
                button2.Text = "altre opzioni";
                ViewQ.selected_linea = number;
                ViewQ.Select_flag = 1;
                ViewQ.tipo_selezione = (int)ViewQ.flagSelez.linea;
                if (MainWindow.formViewQQ != null) MainWindow.formViewQQ.Refresh();

            }
            else
            {
                if (inum >= maxNumSelez)
                {
                    MessageBox.Show("eccessivo numero di linee selezionate");
                    this.Close();
                }
                numSelez[inum] = number;
                ++inum;
                ViewQ.Select_flag = 1;
                ViewQ.tipo_selezione = (int)ViewQ.flagSelez.linea;
                ViewQ.selected_linea = number;
                if (MainWindow.formViewQQ != null) MainWindow.formViewQQ.Refresh();
            }
             
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (option == 0) { 
                Linea_dlg dlg = new Linea_dlg();
                DialogResult dr = dlg.ShowDialog();
                if (dr == DialogResult.No) return;
                this.DialogResult = DialogResult.OK;
                this.Close();
            }
            else 
            {

                ViewQ.unione_linee();
                ViewQ.Select_flag = 1;
                ViewQ.tipo_selezione = (int)ViewQ.flagSelez.linea;
                ViewQ.selected_linea = ViewQ.nShapes-1;
                option = 0;
                inum = 0;
                if (MainWindow.formViewQQ != null) MainWindow.formViewQQ.Refresh();

                this.Close();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if(option == 0)
            {
                textBox1.Visible = true;
                textBox1.Text = "( aggiungi linea )";
                button2.Text = "conferma unione";
                button3.Visible = false;
            }
            option = 1;
            numSelez[inum] = number;
            ++inum;
        }




  
    }
}
